//
//  ZYCConsummateBottomView.m
//  ZDSC
//
//  Created by 张威 on 2021/10/12.
//

#import "ZYCConsummateBottomView.h"
@interface ZYCConsummateBottomView ()

@property (nonatomic, strong) UIButton *lastStepButton;
@property (nonatomic, strong) UIButton *nextStepButton;
@end
@implementation ZYCConsummateBottomView

- (void)setType:(ZYCConsummateBottomType)type{
    _type = type;
    if (type == ZYCConsummateBottomLast) {
        self.lastStepButton.hidden = YES;
        self.nextStepButton.hidden = NO;
        [self.nextStepButton mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(140.0f, 40.0f));
            make.center.equalTo(self);
        }];
    }else if(type == ZYCConsummateBottomNext){
        self.lastStepButton.hidden = NO;
        self.nextStepButton.hidden = YES;
        [self.lastStepButton mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(140.0f, 40.0f));
            make.center.equalTo(self);
        }];
    }else{
        self.lastStepButton.hidden = NO;
        self.nextStepButton.hidden = NO;
        [self.lastStepButton mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(140.0f, 40.0f));
            make.centerY.equalTo(self);
            make.right.equalTo(self.mas_centerX).offset(-20.0f);
        }];
        
        [self.nextStepButton mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(140.0f, 40.0f));
            make.centerY.equalTo(self);
            make.left.equalTo(self.mas_centerX).offset(20.0f);
        }];
    }
    
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self addSubview:self.lastStepButton];
        [self addSubview:self.nextStepButton];
        
        [self.lastStepButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(140.0f, 40.0f));
            make.centerY.equalTo(self);
            make.right.equalTo(self.mas_centerX).offset(-20.0f);
        }];
        
        [self.nextStepButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(140.0f, 40.0f));
            make.centerY.equalTo(self);
            make.left.equalTo(self.mas_centerX).offset(20.0f);
        }];
        
    }
    return self;
}


- (UIButton *)lastStepButton {
    if (!_lastStepButton) {
        _lastStepButton = [[UIButton alloc] init];
        _lastStepButton.frame = CGRectMake(0,0, 140.0f, 40.0f);
        [_lastStepButton setTitle:@"上一步" forState:UIControlStateNormal];
        [_lastStepButton setTitleColor:HEX_RGB(@"FFFFFF") forState:UIControlStateNormal];
        _lastStepButton.titleLabel.font = kCustomFont(@"PingFangSC-Light", 18.0f);
        _lastStepButton.layer.cornerRadius = 20.0f;
        _lastStepButton.layer.masksToBounds = YES;
        CAGradientLayer *gradientLayer = [CAGradientLayer layer];
        gradientLayer.startPoint = CGPointMake(0, 0);
        gradientLayer.endPoint = CGPointMake(1, 0);
        gradientLayer.colors = @[(__bridge id)HEX_RGB(@"#F6EEB0").CGColor,
                                 (__bridge id)HEX_RGB(@"#009B4C").CGColor];
        gradientLayer.locations = @[@(0.3),@(1.0f)];
        gradientLayer.frame = _lastStepButton.bounds;
        gradientLayer.cornerRadius = 20.f;
        [_lastStepButton.layer insertSublayer:gradientLayer atIndex:0];
        [_lastStepButton addTarget:self action:@selector(clickLastStep:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _lastStepButton;
}

- (UIButton *)nextStepButton {
    if (!_nextStepButton) {
        _nextStepButton = [[UIButton alloc] init];
        _nextStepButton.frame = CGRectMake(0,0, 140.0f, 40.0f);
        [_nextStepButton setTitle:@"下一步" forState:UIControlStateNormal];
        [_nextStepButton setTitleColor:HEX_RGB(@"FFFFFF") forState:UIControlStateNormal];
        _nextStepButton.titleLabel.font = kCustomFont(@"PingFangSC-Light", 18.0f);
        _nextStepButton.layer.cornerRadius = 20.0f;
        _nextStepButton.layer.masksToBounds = YES;
        CAGradientLayer *gradientLayer = [CAGradientLayer layer];
        gradientLayer.startPoint = CGPointMake(0, 0);
        gradientLayer.endPoint = CGPointMake(1, 0);
        gradientLayer.colors = @[(__bridge id)HEX_RGB(@"#F6EEB0").CGColor,
                                 (__bridge id)HEX_RGB(@"#009B4C").CGColor];
        gradientLayer.locations = @[@(0.3),@(1.0f)];
        gradientLayer.frame = _nextStepButton.bounds;
        gradientLayer.cornerRadius = 20.f;
        [_nextStepButton.layer insertSublayer:gradientLayer atIndex:0];
        [_nextStepButton addTarget:self action:@selector(clickNextStep:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _nextStepButton;
}


- (void)clickLastStep:(UIButton *)sender{
    if ([self.delegate respondsToSelector:@selector(consummateBottomViewDidLast)]) {
        [self.delegate consummateBottomViewDidLast];
    }
}

- (void)clickNextStep:(UIButton *)sender{
    if ([self.delegate respondsToSelector:@selector(consummateBottomViewDidNext)]) {
        [self.delegate consummateBottomViewDidNext];
    }
}
@end
